package com.lw.leetcode.二叉树;

import com.lw.leetcode.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2024</p>
 * <p>Company: https://www.lw.com/</p>
 * <p>
 * 时间复杂度：O()
 * 空间复杂度：O()
 *
 * @author lw
 * @date 2024/6/17 15:30
 */
public class _94_二叉树的中序遍历 {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> retList = new ArrayList<>();

        inorder(root, retList);

        return retList;
    }

    private void inorder(TreeNode node, List<Integer> list) {
        if (node == null) return;
        inorder(node.left, list);
        list.add(node.val);
        inorder(node.right, list);
    }
}
